package com.apps.gomdiem.common;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import com.apps.gomdiem.R;

public class DialogUtils {

	public static Dialog makeConfirm(Context ctx, int msgId, OnConfirmListener l) {
		return makeConfirm(ctx, ctx.getString(msgId), l);
	}
	public static Dialog makeConfirm(Context ctx, String msg, final OnConfirmListener l) {
		OnClickListener clickListener = new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				switch (which) {
				case DialogInterface.BUTTON_POSITIVE:
					if (l != null)
						l.onOk();
					break;
				case DialogInterface.BUTTON_NEGATIVE:
					if (l != null)
						l.onCancel();
					break;
				}
				dialog.dismiss();
			}
		};
		Builder builder = new Builder(ctx);
		builder.setMessage(msg)
				.setPositiveButton(R.string.ok, clickListener)
				.setNegativeButton(R.string.cancel, clickListener);
		return builder.create();
	}
	public interface OnConfirmListener {
		void onOk();
		void onCancel();
	}
}